unit Con_Banco;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls,
  Db, DbTables, TFlatButtonUnit;

type
  TFrmCon_Banco = class(TFrmConsulta)
    Label1: TLabel;
    edtNome: TEdit;
    dbgBanco: TDBGrid;
    btnGravar: TFlatButton;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure edtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnGravarClick(Sender: TObject);
  private
    procedure FazConsulta;
  public
    Ban_Codigo: string;
  end;

var
  FrmCon_Banco: TFrmCon_Banco;

implementation

uses Dm, Biblio, clsBanco, Cad_Banco, menu;

var
  Banco: TBanco;
  tds: Tdatasource;
  tq: Tquery;

{$R *.DFM}

procedure TFrmCon_Banco.BtnFecharClick(Sender: TObject);
begin
  Ban_Codigo := tq.fieldbyname('Ban_Codigo').asstring;
  inherited;
end;

procedure TFrmCon_Banco.FazConsulta;
begin
  if edtnome.text = '' then edtnome.text := ' ';
  Banco.Consultar(tq, edtnome.text);
end;

procedure TFrmCon_Banco.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  Banco := TBanco.Create;
  tds := TDataSource.create(self);
  tq := Tquery.create(self);
  tq.databasename := dmint.db.databasename;
  tds.DataSet := tq;
  dbgBanco.DataSource := tds;
  fazconsulta;
  edtnome.setfocus;
end;

procedure TFrmCon_Banco.edtNomeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if key = 12 then FazConsulta;
end;

procedure TFrmCon_Banco.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Banco.free;
  tds.free;
  tq.free;
end;

procedure TFrmCon_Banco.btnGravarClick(Sender: TObject);
var
  f1: TfrmCad_Banco;
begin
  inherited;
  f1 := TfrmCad_Banco.Create(Self);
  f1.btnC_Banco.Visible := False;
  f1.ShowModal;
  f1.Free;
  FazConsulta;
end;

end.
